﻿using UnityEditor;
using UnityEngine;

namespace CWM.Skinn
{
    public static partial class SkinnContextCommands
    {
        [CtxMenuItem("Renderer/Mesh/Vertices/Weld/Low Precision",
           "Removes duplicate vertices with matching vertex information. " +
           "Low precision is for large meshes; ie environmental models."
            , 0)]
        public static void RendererWeldLow()
        {
            foreach (var item in SkinnContext.GetContextItems())
            {
                var context = item.GetComponent<Renderer>();
                if (SkinnEx.IsNullOrNotInAScene(context)) continue;
                if (!SkinnEx.HasMinimumRequirements(context)) continue;
                SkinnContext.UndoRecord(context, "Weld Low");
                context.SetSharedMesh(context.GetSharedMesh().Weld(true));
            }
            SkinnContext.Finished();
        }

        [CtxMenuItem("Renderer/Mesh/Vertices/Weld/High Precision",
           "Removes duplicate vertices with matching vertex information. " +
           "High precision is for small meshes; ie character models."
            , 0)]
        public static void RendererWeldHigh()
        {
            foreach (var item in SkinnContext.GetContextItems())
            {
                var context = item.GetComponent<Renderer>();
                if (SkinnEx.IsNullOrNotInAScene(context)) continue;
                if (!SkinnEx.HasMinimumRequirements(context)) continue;
                SkinnContext.UndoRecord(context, "Weld High");
                context.SetSharedMesh(context.GetSharedMesh().Weld(false));
            }
            SkinnContext.Finished();
        }
    }
}